package idiet.dao.hibernate;

import idiet.bean.CustomerPal;
import idiet.bean.FoodIngredientElement;
import idiet.bean.Rni;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("rniDao")
public class RniDao extends BaseDao{
	public Rni getRniByRniId(int rniId){
		return (Rni) this.sessionFactory
				.openSession()
				.createCriteria(Rni.class)
				.add(Restrictions.eq("id", rniId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<Rni> getRnis(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Rni.class)
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<Rni> getRnis(int age){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Rni.class)
				.add(Restrictions.gt("upperAge", age))
				.add(Restrictions.le("lowerAge", age))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<Rni> getRnis(CustomerPal pal){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Rni.class)
				.add(Restrictions.eq("customerPal", pal))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<Rni> getRnis(FoodIngredientElement element){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Rni.class)
				.add(Restrictions.eq("foodIngredientElement", element))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<Rni> getRnis(int age,FoodIngredientElement element){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(Rni.class)
				.add(Restrictions.le("upperAge", age))
				.add(Restrictions.ge("lowerAge", age))
				.add(Restrictions.eq("foodIngredientElement", element))
				.list();
	}
	public void createRni(Rni rni){
		this.sessionFactory
		.getCurrentSession()
		.save(rni);
	}
	public void deleteRni(Rni rni){
		this.sessionFactory
		.getCurrentSession()
		.delete(rni);
	}
	public void updateRni(Rni rni){
		this.sessionFactory
		.getCurrentSession()
		.update(rni);
	}
}
